//
//  JXItemDetailViewController.m
//

#import "JXItemDetailViewController.h"

#import "JXWorkgroupListController.h"
#import "JXChatViewController.h"
#import "JXHistoricalVisitManager.h"
#import "JXLocalPushManager.h"
#import "JXMCSUserManager.h"
#import "JXTool.h"

@interface JXItemDetailViewController ()<JXClientDelegate>

@property(nonatomic, strong) UIImage *goodImage;
@property(nonatomic, strong) NSMutableArray *indexContainer;

@end

@implementation JXItemDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"商品详情"];
    [self setupDefaultLeftButtonItem];
    ;
    _indexContainer = [NSMutableArray
            arrayWithArray:[JXHistoricalVisitManager sharedInstance].historys];
    [_indexContainer addObject:[NSNumber numberWithInteger:self.selectedIndexPath]];
    [[JXHistoricalVisitManager sharedInstance] setHistorys:_indexContainer];
    [[NSUserDefaults standardUserDefaults] synchronize];

    UIImageView *bgView =
            [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 64)];
    bgView.userInteractionEnabled = YES;
    if (self.selectedIndexPath) {
        NSString *imageName = [NSString stringWithFormat:@"%ldInfo", (long)self.selectedIndexPath];
        bgView.image = JXGetSuitableImage(imageName);
    }

    UIButton *chatBtn = [[UIButton alloc]
            initWithFrame:CGRectMake(0, self.view.height - 60 - 64, 120, 60)];
    [chatBtn addTarget:self action:@selector(requestCSForUI) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:chatBtn];

    [self.view addSubview:bgView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:JXImage(@"basicNav")
                                                  forBarMetrics:UIBarMetricsDefault];
}

- (void)requestCSForUI {
 [[JXMCSUserManager sharedInstance] requestCSForUI:self.navigationController indexPath:self.selectedIndexPath];
}

@end
